import React, { Component } from "react";
import { Link, Route, Switch, Redirect } from "react-router-dom";

class Home extends Component {
  render() {
    return <div>这是首页页面</div>;
  }
}

class About extends Component {
  render() {
    return <div>这是关于页面</div>;
  }
}

class Mine extends Component {
  render() {
    return <div>这是我的页面</div>;
  }
}

class App extends Component {
  render() {
    return (
      <>
        <h2>react-router-重定向</h2>
        <ul>
          <li>
            <Link to="/home">home</Link>
          </li>
          <li>
            <Link to="/about">about</Link>
          </li>
          <li>
            <Link to="/mine">mine</Link>
          </li>
        </ul>

        <hr />

        {/* Redirect表示重定向，是和Route并列的地方 */}
        {/* from类似于path(匹配)的效果 */}
        {/* 使用Redirect的时候要加上exact */}
        <Switch>
          <Redirect from="/" to="/home" exact></Redirect>
          <Route path="/home" component={Home}></Route>
          <Route path="/about" component={About}></Route>
          <Route path="/mine" component={Mine}></Route>
        </Switch>
      </>
    );
  }
}

export default App;
